package com.kc.business.service.impl;

import com.kc.business.domain.BizLiteraryEnterForm;
import com.kc.business.domain.BizUser;
import com.kc.business.mapper.BizLiteraryEnterMapper;
import com.kc.business.mapper.BizUserMapper;
import com.kc.business.service.IBizLiteraryEnterService;
import com.kc.common.constant.BizConstants;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/9/25
 */
@Service
public class BizLiteraryEnterServiceImpl implements IBizLiteraryEnterService {

    @Resource
    BizLiteraryEnterMapper literaryEnterMapper;
    @Resource
    BizUserMapper userMapper;

    /**
     * 墨客入驻列表
     *
     * @param literaryEnter
     * @return
     */
    @Override
    public List<BizLiteraryEnterForm> getList(BizLiteraryEnterForm literaryEnter) {
        return literaryEnterMapper.select(literaryEnter);
    }

    /**
     * 墨客入驻审核
     *
     * @param literaryEnter
     * @return
     */
    @Override
    @Transactional
    public int edit(BizLiteraryEnterForm literaryEnter) {
        if (BizConstants.PASS_VERIFY.equals(literaryEnter.getStatus())) {
            BizLiteraryEnterForm _literaryEnter = literaryEnterMapper.selectByPrimaryKey(literaryEnter.getEnterId());
            int useId = _literaryEnter.getUserId();
            BizUser bizUser = new BizUser();
            bizUser.setId(useId);
            bizUser.setIsLiterary(BizConstants.YES);
            userMapper.updateByPrimaryKeySelective(bizUser);
        }
        return literaryEnterMapper.updateByPrimaryKeySelective(literaryEnter);
    }
}
